import json
import logging.config
import os
from static import PROJECT_PATH
import time
from common.utils.log_util.log_config import LogConfig


class LogUtil:
    @classmethod
    def setup_logging(cls, config_info=LogConfig.config, default_level=logging.INFO, env_key='LOG_CFG'):
        """Setup logging configuration"""
        value = os.getenv(env_key)
        if value:
            path = value
        if not config_info and os.path.exists(path):
            with open(path, 'rt') as f:
                config_info = json.load(f)
        if config_info:
            logging.config.dictConfig(config_info)
        else:
            logging.basicConfig(level=default_level)


def get_logger():
    LogUtil.setup_logging()
    my_logger = logging.getLogger('my_logger')
    return my_logger


if __name__ == '__main__':
    # 获取当前文件所在目录
    print(os.getcwd())
    # 获取当前文件路径
    print(os.path.abspath(__file__))
    LogUtil.setup_logging()
    logger = logging.getLogger('my_module')
    count = 5
    while count > 0:
        logger.error('打印日志')
        time.sleep(1)
        count -= 1
